package com.example.espressotests

import android.annotation.SuppressLint
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        initView()
    }

    @SuppressLint("SetTextI18n")
    private fun initView() {
        btn.setOnClickListener {
            val edit1Value = edit1?.text?.toString()
            val edit2Value = edit2?.text?.toString()
            if (!edit1Value.isNullOrEmpty() && !edit2Value.isNullOrEmpty())
                edit1Value.toInt().let { v1 ->
                    edit2Value.toInt().let { v2 ->
                        text1.text = "结果：${v1 + v2}"
                    }
                }
        }

        btn2.setOnClickListener {
            startActivity(
                Intent(this, MyWebViewActivity::class.java).putExtra(
                    "url",
                    "https://www.baidu.com/"
                )
            )
        }

        btn3.setOnClickListener {
            startActivity(Intent(this, MyListActivity::class.java))
        }
    }
}
